package ifrn.pdsd.android.extranet;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;

public class MenuActivity extends Activity {

	public static final int MENU1 = Menu.FIRST;
	public static final int MENU2 = Menu.FIRST + 1;
	public static final int MENU3 = Menu.FIRST + 3;
	public static final int MENU4 = Menu.FIRST + 4;
	public static final int MENU5 = Menu.FIRST + 5;

	ImageButton ibTarefas, ibFuncionarios;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_menu);

		this.ibTarefas = (ImageButton) findViewById(R.id.imageButtonTarefas);
		ibTarefas.setOnClickListener(new OnClickListener() {
 
			@Override
			public void onClick(View v) {
				TelaEspera processo = new TelaEspera(MenuActivity.this);
				processo.execute(3000, 2000, 4000);
				
				startActivity(new Intent(MenuActivity.this,
						SelecionarProjetoActivity.class));
			}
		});

		this.ibFuncionarios = (ImageButton) findViewById(R.id.imageButtonFuncionarios);
		ibFuncionarios.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				TelaEspera processo = new TelaEspera(MenuActivity.this);
				processo.execute(3000, 2000, 4000);
				
				startActivity(new Intent(MenuActivity.this,
						ListarFuncActivity.class));
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(0, MENU1, 0, "Sobre");
		menu.add(0, MENU2, 0, "Sair");
		
		// Sub Menu
		SubMenu sub = menu.addSubMenu("Opcoes");
		sub.add(0, MENU3, 0, "Extranet Web");
		sub.add(0, MENU4, 0, "Site Ponto Criativo");

		menu.add(0, MENU5, 0, "Ajuda");
		return super.onCreateOptionsMenu(menu);
	}

	public boolean onOptionsItemSelected(MenuItem item) {

		switch (item.getItemId()) {
		case MENU1:
			Toast.makeText(this, "Falar sobre o sistema. ",
					Toast.LENGTH_LONG).show();
			return true;
		case MENU2:
			//Toast.makeText(this, "Sai ;)", Toast.LENGTH_LONG).show();
			//finish();
			startActivity(new Intent(MenuActivity.this,
					LoginActivity.class));
			return true;
		case MENU3:
			// Intent mudarDeTela = new Intent(this, Tela2.class);
			// startActivity(mudarDeTela);
			siteExtranetWeb();
			return true;
		case MENU4:
			sitePontoCriativo();
			return true;
		}
		return false;
	}

	void sitePontoCriativo() {
		String end = "http://pontocriativo.com.br//";
		Uri uri = Uri.parse(end);
		Intent it = new Intent(Intent.ACTION_VIEW, uri);
		startActivity(it);
	}

	void siteExtranetWeb() {
		String end = "http://10.17.1.200:9000/";
		Uri uri = Uri.parse(end);
		Intent it = new Intent(Intent.ACTION_VIEW, uri);
		startActivity(it);
	}

}
